import 'package:flutter/material.dart';

/// 数据Provider，如果要传多个数据可以用date_provider2.dart
class DataProvider<T> extends InheritedWidget {
  final T data;

  DataProvider({Key key, @required Widget child, this.data})
      : super(key: key, child: child);

  @override
  bool updateShouldNotify(DataProvider oldWidget) {
    return data != oldWidget.data;
  }

  static T of<T>(BuildContext context) {
    return (context.inheritFromWidgetOfExactType(DataProvider<T>().runtimeType)
            as DataProvider<T>)
        .data;
  }
}
